import React, { Component } from 'react'
import Interaction from './Interaction'
import Warning from './Warning'

let alertWindow
class AlertWindow extends Component {
	state = {
		IToClose: true,
		ICloseEffect: undefined,
		IExecuteFunc: undefined,
		IContent: null,
		IShow: false,
		WToClose: true,
		WCloseEffect: undefined,
		WExecuteFunc: undefined,
		WContent: null,
		WShow: false,
	}
	render() {
		alertWindow = this
		return (
			<>
				<Interaction
					toClose={this.state.IToClose}
					executeFunc={this.state.IExecuteFunc}
					closeEffect={this.state.ICloseEffect}
					show={this.state.IShow}
				>
					{this.state.IContent}
				</Interaction>
				<Warning
					toClose={this.state.WToClose}
					executeFunc={this.state.WExecuteFunc}
					closeEffect={this.state.WCloseEffect}
					show={this.state.WShow}
				>
					{this.state.WContent}
				</Warning>
			</>
		)
	}
}
function alertInteraction(IContent, IExecuteFunc, IToClose, ICloseEffect) {
	alertWindow.setState({
		IContent,
		IExecuteFunc,
		IToClose,
		ICloseEffect,
		IShow: true,
	})
}
function alertWarning(WContent, WExecuteFunc, WToClose, WCloseEffect) {
	alertWindow.setState({
		WContent,
		WExecuteFunc,
		WToClose,
		WCloseEffect,
		WShow: true,
	})
}
// 组件结构清晰，如果父级层级高,组件复杂就使用组件，层级低就使用函数调用
export { Interaction, Warning, AlertWindow, alertInteraction, alertWarning }
